//
//  EFBGestureView.m
//  Pods
//
//  Created by E.F.B on 15-5-27.
//
//

#import "EFBGestureView.h"

@implementation EFBGestureView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UITapGestureRecognizer* singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTap:)];
        singleRecognizer.numberOfTapsRequired = 1;
        singleRecognizer.delegate = self;
        [self addGestureRecognizer:singleRecognizer];
        
        /*
        UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
        UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
        
        leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        
        leftSwipeGestureRecognizer.numberOfTouchesRequired = 2;
        rightSwipeGestureRecognizer.numberOfTouchesRequired = 2;
        
        leftSwipeGestureRecognizer.delegate = self;
        rightSwipeGestureRecognizer.delegate = self;

        
        [self addGestureRecognizer:leftSwipeGestureRecognizer];
        [self addGestureRecognizer:rightSwipeGestureRecognizer];
        */
        
//        UIPanGestureRecognizer *panGestureRecognizer =[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
//        panGestureRecognizer.minimumNumberOfTouches = 2;
//        panGestureRecognizer.maximumNumberOfTouches = 2;
//        [self addGestureRecognizer:panGestureRecognizer];
    }
    return self;
}

- (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
//    NSLog(@"PAN");
}

- (void)SingleTap:(UITapGestureRecognizer*)recognizer
{
    if (_delegate) {
        [_delegate gestureForTap:recognizer];
    }
}

- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{
//    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//      
//    }
//    
//    if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
//
//    }
//    NSLog(@"sssssss111111");

    if (_delegate) {
        [_delegate gestureForSwipe:sender];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
//    NSLog(@"sssssss");
    if (touches.count == 1) // Show selection on single touch
	{
//        UITouch *touch = [touches anyObject]; // Get touch from set
//        NSArray *array = [touch gestureRecognizers];
//        
//        NSSet *a = [event allTouches];
//        
//        NSLog(@"22222sssssss");
//        [self.nextResponder touchesBegan:touches withEvent:event];

    }
}



-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
//    NSLog(@" ========  %@",NSStringFromClass([touch.view class]));
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
        
        return NO;
        
    }
    
    return YES;   
    
}

//- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
//- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
